<?php
class SearchAction extends Action {

	public function _initialize() {

    }
	public function index() {
		$this->assign('_header_tab_on_index',1);
		$index = empty($_GET['index'])?'All':$_GET['index'];
		$this->assign('index_active',$index);
		$this->display();
    }
	public function autofind() {
		$q = strtolower($_GET["q"]);
		if(!empty($q)){
			$limit = empty($_GET["limit"])? 10 : $_GET["limit"];
			$start = empty($_GET["start"])? 0 : $_GET["start"];
			$status = (isset($_GET["status"]) && trim($_GET["status"]) != '')?(($_GET["status"] == 'all')?"":" AND corp_status=".$_GET["status"]."") :" AND corp_status=1";
			$timestamp = $_GET["timestamp"];
			$model = M('CorpBase');
			$items = $model->where("((corp_name_cn LIKE '%".$q."%') OR (corp_name_en LIKE '%".$q."%'))".$status)->limit($start.', '.$limit)->findAll();
			foreach($items as $value){
					echo $value['corp_name_cn']."|".$value['corp_id']."\n";
			}
		}
	}
}
